<template>
  <div class="parent">
    <echartsDom v-if="isShowEcharts" style="width: 100%; height: 100%" :width="width" :height="height" :option="option" :type="type" />
    <div v-else>
      <px-empty :image-size="200" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, ref, watch } from "vue";
import echartsDom from "./echartsDom.vue";
const props = defineProps({
  width: {
    type: String,
    default: ""
  },
  height: {
    type: String,
    default: ""
  },
  color: {
    type: String,
    default: "#3B82F6"
  },
  type: {
    type: String,
    default: ""
  },
  chartlist: {
    type: Object,
    required: true
  }
});

const isShowEcharts = ref(false);
const state = reactive({
  option: {},
  yAxis: []
});
const { option, yAxis } = toRefs(state);

const getoptions = () => {
  if (props.chartlist != null) {
    isShowEcharts.value = true;
  } else {
    isShowEcharts.value = false;
  }
  option.value = {
    title: {
      show: true,
      text: props.chartlist.xaxis[0],
      textAlign: "left"
    },
    xAxis: {},
    yAxis: {},
    series: [
      {
        symbolSize: 10,
        type: "scatter",
        data: props.chartlist.series
      }
    ]
  };
};
watch(
  () => props.chartlist,
  newOption => {
    getoptions();
  },
  {
    immediate: true
  }
);
</script>

<style scoped lang="scss">
.parent {
  position: relative;
  float: left;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.topIcon {
  position: absolute;
  top: 7px;
  right: 8px;
  width: 20px;
  cursor: pointer;
}

.linediv {
  position: relative;
  float: left;
  width: 23px;
  height: 17px;
  margin-right: 10px;

  .line {
    position: absolute;
    top: 8px;
    width: 100%;
    height: 1px;
    background: #3b82f6;
  }

  .yuan {
    position: absolute;
    top: 6px;
    left: 9px;
    width: 5px;
    height: 5px;
    background: #3b82f6;
    border-radius: 50%;
  }
}
</style>
